<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var appCashLogDataGrid;
    $(function() {
        appCashLogDataGrid = $('#appCashLogDataGrid').datagrid({
            url : '${path }/appCashLog/dataGrid',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            frozenColumns : [ [ {
                title : 'id',
                field : 'id',
                width : 40,
                hidden : true
            } ] ],
            columns : [ [{
                width : '150',
                title : '日期',
                field : 'createTime',
                sortable : true
            },{
                field : 'vipCode',
                title : '编号',
                width : 170
            },{
                field : 'taxationName',
                title : '手续费',
                width : 100
            }, {
                field : 'percentage',
                title : '费率',
                width : 70
            },{
                width : '100',
                title : '状态',
                field : 'status',
                sortable : true,
                formatter : function(value, row, index) {
                    switch (value) {
                        case 0:
                            return '待审';
                        case 1:
                            return '审核通过';
                        case 1:
                            return '审核未通过';
                    }
                }
            }, {
                field : 'action',
                title : '操作',
                width : 200,
                formatter : function(value, row, index) {
                    var str = '';
                    switch(row.status){
                        case 0 :
                                str += $.formatString('<a href="javascript:void(0)" class="appCashLog-easyui-linkbutton-agree"  data-options="plain:true,iconCls:\'fi-pencil icon-blue\'"  onclick="agreeAppCashLogFun(\'{0}\');" >通过</a>', row.id);
                                str += '&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;';
                                str += $.formatString('<a href="javascript:void(0)" class="appBase-easyui-linkbutton-refuse" data-options="plain:true,iconCls:\'fi-x icon-red\'"  onclick="refuseAppCashLogFun(\'{0}\');" >拒绝</a>', row.id);
                            break;
                        case 1 :
                            str += $.formatString('<a href="javascript:void(0)" class="appCashLog-easyui-linkbutton-agree"  data-options="plain:true,iconCls:\'fi-pencil icon-blue\'"    >通过</a>', row.id);
                            str += '&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;';
                            str += $.formatString('<a href="javascript:void(0)" class="appBase-easyui-linkbutton-refuse" data-options="plain:true,iconCls:\'fi-x icon-red\'"    >拒绝</a>', row.id);
                            break;
                        case  2:
                            str += $.formatString('<a href="javascript:void(0)" class="appCashLog-easyui-linkbutton-agree"  data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" >通过</a>', row.id);
                            str += '&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;';
                            str += $.formatString('<a href="javascript:void(0)" class="appBase-easyui-linkbutton-refuse" data-options="plain:true,iconCls:\'fi-x icon-red\'"   >拒绝</a>', row.id);
                            break;
                    }
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.appCashLog-easyui-linkbutton-agree').linkbutton({text:'通过'});
                $('.appCashLog-easyui-linkbutton-refuse').linkbutton({text:'拒绝'});
            },
        });
    });

    function agreeAppCashLogFun(id) {
        if (id == undefined) {
            var rows = appCashLogDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            appCashLogDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }

        parent.$.messager.confirm('询问', '审核通过，是否继续？', function(b) {
            if (b) {
                $.post('${path }/appCashLog/agree', {
                    id : id
                }, function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        appCashLogDataGrid.datagrid('reload');
                    }
                }, 'JSON');
            }
        });
    }

    function refuseAppCashLogFun(id) {
        $.messager.prompt("操作提示", "您确定拒绝嘛？将返还积分，", function (data) {
            console.info(data);
            if (data) {
                alert("确定");
               $.post('${path }/appCashLog/refuse', {
                    id : id,
                    remark : data
                }, function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        appCashLogDataGrid.datagrid('reload');
                    }
                    progressClose();
                }, 'JSON');
            }
            else {
                alert("取消");
            }
        });
    }

</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',fit:true,border:false">
        <table id="appCashLogDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
